import numpy as np
import pandas as pd
from NeuronNetwork import NeuronNetwork

def test(name):
    path = './data/' + name + ".csv"
    data = pd.read_csv(path, 'utf-8')
    data = data.values.tolist()
    neuron_train_x = []
    neuron_train_y = []
    for d in data[0:int(0.8*len(data))]:
        d = list(map(float,d[0].split(',')))
        neuron_train_x.append(d[0:-1])
        neuron_train_y.append(d[-1])
    neuron_test_x = []
    neuron_test_y = []
    for d in data[int(0.8*len(data)):len(data)]:
        d = list(map(float, d[0].split(',')))
        neuron_test_x.append(d[0:-1])
        neuron_test_y.append(d[-1])

    #print(neuron_train_x)
    #print(neuron_train_y)

    NN = NeuronNetwork(len(neuron_train_x[0]), 2*len(neuron_train_x[0]), 1)
    NN.train(
        neuron_train_x,
        neuron_train_y,
        eta=1,
        threshold=1e-7,
    )
    res=NN.predict(neuron_test_x)
    for r in range(len(res)):
        print(res[r],neuron_test_y[r])

if __name__=='__main__':
    #names=['liver','iris','glasss','heart','cleveland']
    #names=['cleveland']
    names=['liver']
    for name in names:
       #pre.pre(name)
       test(name)